package cn.hznc.controller.Retrospect;

import cn.hznc.domain.request.retrospect.ToolRestrospectReq;
import cn.hznc.domain.request.retrospect.ToolRetrospectIndexReq;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.controller.service.retrospect.ToolRetrospectService;
import cn.hznc.exception.ToolLifeCycleException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：Administrator
 * @Date：2023/4/12 11:33
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/toolRetrospect")
public class ToolRetrospectController{

    @Autowired
    private ToolRetrospectService toolRetrospectService;

    @RequestMapping(value = "/getToolRetrospectAllList",method = RequestMethod.POST)
    public ResponseBody getToolRetrospectAllList(@RequestBody ToolRestrospectReq ToolRestrospectReq){
        return ResponseBody.success(toolRetrospectService.getToolRetrospectAllList(ToolRestrospectReq));
    }

    @RequestMapping(value = "/qryConditionType",method = RequestMethod.GET)
    public ResponseBody qryConditionType(@RequestParam("filter") String filter){
        return ResponseBody.success(toolRetrospectService.qryConditionType(filter));
    }

    @RequestMapping(value = "/getToolRetrospectIndex",method = RequestMethod.POST)
    public ResponseBody getToolRetrospectIndex(@RequestBody ToolRetrospectIndexReq toolRetrospectIndexReq){
        return ResponseBody.success(toolRetrospectService.getToolRetrospectIndex(toolRetrospectIndexReq));
    }

    /**
     * 总成使用历史详情
     * @param uniqueId
     * @return
     */
    @RequestMapping(value = "/getToolRetrospectDetail",method = RequestMethod.GET)
    public ResponseBody getToolRetrospectDetail(@RequestParam("uniqueId") String uniqueId){
        return ResponseBody.success(toolRetrospectService.getToolRetrospectDetail(uniqueId));
    }

    /**
     * 零件使用历史详情
     * @param uniqueId
     * @return
     */
    @RequestMapping(value = "/getToolPartRetrospectDetail",method = RequestMethod.GET)
    public ResponseBody getToolPartRetrospectDetail(@RequestParam("uniqueId") String uniqueId){
        try {
            return ResponseBody.success(toolRetrospectService.getToolPartRetrospectDetail(uniqueId));
        } catch (ToolLifeCycleException e) {
            return ResponseBody.error(e.getCode() , e.getMsg());
        }
    }
}
